﻿using STT.Debug;
using STT.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace STT
{
    // Token: 0x02000047 RID: 71
    public class ArbreModules : TreeView
    {
        // Token: 0x060001C3 RID: 451 RVA: 0x0000F55C File Offset: 0x0000E55C
        private void ScanChildNodes(TreeNode node_base, ArbreModules.f_bool_treenode_array_obj callback, ref bool flag, object ob_user)
        {
            if (flag && node_base != null)
            {
                flag = callback(node_base, ob_user);
                if (flag)
                {
                    foreach (object obj in node_base.Nodes)
                    {
                        TreeNode node_base2 = (TreeNode)obj;
                        this.ScanChildNodes(node_base2, callback, ref flag, ob_user);
                        if (!flag)
                        {
                            break;
                        }
                    }
                }
            }
        }

        // Token: 0x060001C4 RID: 452 RVA: 0x0000F5D4 File Offset: 0x0000E5D4
        private bool ScanTree(TreeNode node_base, ArbreModules.f_bool_treenode_array_obj callback, object ob_user)
        {
            bool flag = true;
            if (node_base != null)
            {
                TreeNode treeNode = node_base;
                this.ScanChildNodes(node_base, callback, ref flag, ob_user);
                if (!flag)
                {
                    return flag;
                }
                while (treeNode.Parent != null)
                {
                    int num = treeNode.Parent.Nodes.IndexOf(treeNode) + 1;
                    while (num >= 0 && num < treeNode.Parent.Nodes.Count)
                    {
                        this.ScanChildNodes(treeNode.Parent.Nodes[num], callback, ref flag, ob_user);
                        if (!flag)
                        {
                            return flag;
                        }
                        num++;
                    }
                    treeNode = treeNode.Parent;
                }
            }
            return flag;
        }

        // Token: 0x060001C5 RID: 453 RVA: 0x0000F65C File Offset: 0x0000E65C
        private TreeNode GetNext(TreeNode node_base)
        {
            TreeNode result = null;
            if (node_base != null)
            {
                if (node_base.Nodes.Count > 0)
                {
                    result = node_base.Nodes[0];
                }
                else
                {
                    while (node_base.Parent != null)
                    {
                        int num = node_base.Parent.Nodes.IndexOf(node_base);
                        if (num >= 0)
                        {
                            num++;
                            if (num < node_base.Parent.Nodes.Count)
                            {
                                result = node_base.Parent.Nodes[num];
                                break;
                            }
                        }
                        node_base = node_base.Parent;
                    }
                }
            }
            return result;
        }

        // Token: 0x060001C6 RID: 454 RVA: 0x0000F6DD File Offset: 0x0000E6DD
        public bool FindNextString(DialogBoxFind.RequestFindText request_scan)
        {
            if (!string.IsNullOrEmpty(request_scan.word_regex))
            {
                if (base.SelectedNode == null)
                {
                    base.SelectedNode = this.Root;
                }
                return this.FindStringFromNode(this.GetNext(base.SelectedNode), request_scan);
            }
            return false;
        }

        // Token: 0x060001C7 RID: 455 RVA: 0x0000F716 File Offset: 0x0000E716
        public bool FindString(DialogBoxFind.RequestFindText request_scan)
        {
            return !string.IsNullOrEmpty(request_scan.word_regex) && this.FindStringFromNode(base.SelectedNode, request_scan);
        }

        // Token: 0x060001C8 RID: 456 RVA: 0x0000F738 File Offset: 0x0000E738
        private bool FindStringOfTreeCallBack(TreeNode node_base, object ob_user)
        {
            DialogBoxFind.RequestFindText requestFindText = (DialogBoxFind.RequestFindText)ob_user;
            if (!string.IsNullOrEmpty(requestFindText.word_regex))
            {
                if (requestFindText.flag_use_regex)
                {
                    Regex regex = new Regex(requestFindText.word_regex);
                    Match match = regex.Match(node_base.Text);
                    if (match.Success)
                    {
                        base.SelectedNode = node_base;
                        Interaction.DisplayViewerPanel();
                        base.Focus();
                        return false;
                    }
                }
                else
                {
                    StringComparison comparisonType = StringComparison.CurrentCultureIgnoreCase;
                    if (requestFindText.flag_match_case)
                    {
                        comparisonType = StringComparison.CurrentCulture;
                    }
                    int num = node_base.Text.IndexOf(requestFindText.word_regex, comparisonType);
                    if (num != -1)
                    {
                        if (!requestFindText.flag_match_whole_text)
                        {
                            base.SelectedNode = node_base;
                            Interaction.DisplayViewerPanel();
                            base.Focus();
                            return false;
                        }
                        if (num == 0 && requestFindText.word_regex.Length == node_base.Text.Length)
                        {
                            base.SelectedNode = node_base;
                            Interaction.DisplayViewerPanel();
                            base.Focus();
                            return false;
                        }
                    }
                }
            }
            return true;
        }

        // Token: 0x060001C9 RID: 457 RVA: 0x0000F818 File Offset: 0x0000E818
        public bool FindStringFromNode(TreeNode node_base, DialogBoxFind.RequestFindText request_scan)
        {
            bool flag;
            if (!string.IsNullOrEmpty(request_scan.word_regex))
            {
                if (node_base == null)
                {
                    node_base = this.Root;
                }
                flag = this.ScanTree(node_base, new ArbreModules.f_bool_treenode_array_obj(this.FindStringOfTreeCallBack), request_scan);
            }
            else
            {
                flag = false;
            }
            return !flag;
        }

        // Token: 0x060001CA RID: 458 RVA: 0x0000F864 File Offset: 0x0000E864
        private void Create_MenuFlottant()
        {
            this.ContextMenuStrip.Items.Clear();
            this.Remove_Module_MenuFlottant.Tag = null;
            if (base.SelectedNode == null)
            {
                base.SelectedNode = this.Root;
            }
            if (base.SelectedNode is ModuleSymbols)
            {
                this.Remove_Module_MenuFlottant.Tag = base.SelectedNode;
                this.Remove_Module_MenuFlottant.Text = "Remove " + base.SelectedNode.Text;
                this.ContextMenuStrip.Items.Add(this.Remove_Module_MenuFlottant);
                this.Translate_Module_MenuFlottant.Tag = base.SelectedNode;
                this.Translate_Module_MenuFlottant.Text = "Translate " + base.SelectedNode.Text;
                this.ContextMenuStrip.Items.Add(this.Translate_Module_MenuFlottant);
            }
            else if (base.SelectedNode.Tag is SymUdt)
            {
                SymUdt symUdt = (SymUdt)base.SelectedNode.Tag;
                this.Goto_Structure_MenuFlottant.Tag = base.SelectedNode;
                string str;
                if (symUdt.UniqueName != null)
                {
                    str = symUdt.UniqueName;
                }
                else
                {
                    str = symUdt.SymName;
                }
                this.Goto_Structure_MenuFlottant.Text = "Go to " + str;
                this.ContextMenuStrip.Items.Add(this.Goto_Structure_MenuFlottant);
            }
            else if (base.SelectedNode.Tag is SymEnum)
            {
                SymEnum symEnum = (SymEnum)base.SelectedNode.Tag;
                this.Goto_Structure_MenuFlottant.Tag = base.SelectedNode;
                string str2;
                if (symEnum.UniqueName != null)
                {
                    str2 = symEnum.UniqueName;
                }
                else
                {
                    str2 = symEnum.SymName;
                }
                this.Goto_Structure_MenuFlottant.Text = "Go to " + str2;
                this.ContextMenuStrip.Items.Add(this.Goto_Structure_MenuFlottant);
            }
            else if (base.SelectedNode.Tag is SymFunctionType)
            {
                SymFunctionType symFunctionType = (SymFunctionType)base.SelectedNode.Tag;
                this.Goto_Structure_MenuFlottant.Tag = base.SelectedNode;
                this.Goto_Structure_MenuFlottant.Text = "Go to " + symFunctionType.SymName;
                this.ContextMenuStrip.Items.Add(this.Goto_Structure_MenuFlottant);
            }
            this.ExpandAll_MenuFlottant.Tag = base.SelectedNode;
            this.ContextMenuStrip.Items.Add(this.ExpandAll_MenuFlottant);
            this.CollapseAll_MenuFlottant.Tag = base.SelectedNode;
            this.ContextMenuStrip.Items.Add(this.CollapseAll_MenuFlottant);
        }

        // Token: 0x060001CB RID: 459 RVA: 0x0000FB04 File Offset: 0x0000EB04
        private void Init(TreeNode _root, Control control_parent)
        {
            this.components = new Container();
            this.MenuFlottant = new ContextMenuStrip(this.components);
            this.Remove_Module_MenuFlottant = new ToolStripMenuItem();
            this.Translate_Module_MenuFlottant = new ToolStripMenuItem();
            this.Goto_Structure_MenuFlottant = new ToolStripMenuItem();
            this.ExpandAll_MenuFlottant = new ToolStripMenuItem();
            this.CollapseAll_MenuFlottant = new ToolStripMenuItem();
            this.TreeNavigate = new ArbreModules.Navigate(this);
            this.MenuFlottant.SuspendLayout();
            base.SuspendLayout();
            this.MenuFlottant.Name = "MenuFlottant";
            this.MenuFlottant.Size = new Size(176, 26);
            this.MenuFlottant.Opening += this.MenuFlottant_Opening;
            this.Remove_Module_MenuFlottant.Name = "Remove_Module_MenuFlottant";
            this.Remove_Module_MenuFlottant.Size = new Size(175, 22);
            this.Remove_Module_MenuFlottant.Tag = null;
            this.Remove_Module_MenuFlottant.Text = null;
            this.Remove_Module_MenuFlottant.Click += this.MenuFlottant_Click;
            this.Translate_Module_MenuFlottant.Name = "Translate_Module_MenuFlottant";
            this.Translate_Module_MenuFlottant.Size = new Size(175, 22);
            this.Translate_Module_MenuFlottant.Tag = null;
            this.Translate_Module_MenuFlottant.Text = null;
            this.Translate_Module_MenuFlottant.Click += this.MenuFlottant_Click;
            this.Goto_Structure_MenuFlottant.Name = "Goto_Structure_MenuFlottant";
            this.Goto_Structure_MenuFlottant.Size = new Size(175, 22);
            this.Goto_Structure_MenuFlottant.Tag = null;
            this.Goto_Structure_MenuFlottant.Text = null;
            this.Goto_Structure_MenuFlottant.Click += this.MenuFlottant_Click;
            this.ExpandAll_MenuFlottant.Name = "ExpandAll_MenuFlottant";
            this.ExpandAll_MenuFlottant.Size = new Size(175, 22);
            this.ExpandAll_MenuFlottant.Tag = null;
            this.ExpandAll_MenuFlottant.Text = "Expand All";
            this.ExpandAll_MenuFlottant.Click += this.MenuFlottant_Click;
            this.CollapseAll_MenuFlottant.Name = "CollapseAll_MenuFlottant";
            this.CollapseAll_MenuFlottant.Size = new Size(175, 22);
            this.CollapseAll_MenuFlottant.Tag = null;
            this.CollapseAll_MenuFlottant.Text = "Collapse";
            this.CollapseAll_MenuFlottant.Click += this.MenuFlottant_Click;
            this.ContextMenuStrip = this.MenuFlottant;
            base.HideSelection = false;
            base.ImageList = new ImageList();
            base.ImageList.Images.Add(Resources._default);
            base.ImageList.Images.Add(Resources._module);
            base.ImageList.Images.Add(Resources._member);
            base.ImageList.Images.Add(Resources._enum);
            base.ImageList.Images.Add(Resources._struct);
            base.ImageList.Images.Add(Resources._union);
            base.ImageList.Images.Add(Resources._base_type);
            base.ImageList.Images.Add(Resources._properties);
            base.ImageList.Images.Add(Resources._function);
            base.ImageList.Images.Add(Resources._field);
            base.ImageList.Images.Add(Resources._array);
            base.ImageList.Images.Add(Resources._pointer);
            base.ImageList.Images.Add(Resources._banque);
            if (_root == null)
            {
                this.Root = new TreeNode("Modules");
            }
            else
            {
                this.Root = _root;
            }
            this.Root.ImageIndex = 12;
            this.Root.SelectedImageIndex = 12;
            base.Nodes.Add(this.Root);
            base.AfterSelect += this.This_AfterSelect;
            if (control_parent != null)
            {
                this.PlaceTo(control_parent);
            }
            this.MenuFlottant.ResumeLayout(false);
            base.ResumeLayout(false);
        }

        // Token: 0x060001CC RID: 460 RVA: 0x0000FF1B File Offset: 0x0000EF1B
        public ArbreModules(TreeNode _root, Control control_parent)
        {
            this.Init(_root, control_parent);
        }

        // Token: 0x060001CD RID: 461 RVA: 0x0000FF2B File Offset: 0x0000EF2B
        private void PlaceTo(Control control)
        {
            control.Controls.Add(this);
            this.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
            this.Dock = DockStyle.Fill;
        }

        // Token: 0x1700008E RID: 142
        // (get) Token: 0x060001CE RID: 462 RVA: 0x0000FF48 File Offset: 0x0000EF48
        // (set) Token: 0x060001CF RID: 463 RVA: 0x0000FF50 File Offset: 0x0000EF50
        public TreeNode Root
        {
            get
            {
                return this.root;
            }
            set
            {
                this.root = value;
            }
        }

        // Token: 0x060001D0 RID: 464 RVA: 0x0000FF5C File Offset: 0x0000EF5C
        public void AddNodeToRoot(TreeNode node)
        {
            if (base.FindForm().InvokeRequired)
            {
                base.FindForm().Invoke(new ArbreModules.f_node(this.AddNodeToRoot), new object[]
                {
                    node
                });
                return;
            }
            this.Root.Nodes.Add(node);
        }

        // Token: 0x060001D1 RID: 465 RVA: 0x0000FFAD File Offset: 0x0000EFAD
        public void This_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.TreeNavigate.AddSelectedNode(base.SelectedNode);
            Interaction.Refresh_All_View_Of_Selected_Node();
        }

        // Token: 0x060001D2 RID: 466 RVA: 0x0000FFC8 File Offset: 0x0000EFC8
        private void MenuFlottant_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem toolStripMenuItem = (ToolStripMenuItem)sender;
            if (toolStripMenuItem == this.Remove_Module_MenuFlottant)
            {
                DialogResult dialogResult = MessageBox.Show("Do you really want to remove the module : " + ((ModuleSymbols)this.Remove_Module_MenuFlottant.Tag).Text + " ?", "Question.", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    base.Nodes.Remove((TreeNode)this.Remove_Module_MenuFlottant.Tag);
                    this.TreeNavigate.RefreshNavigate();
                    return;
                }
            }
            else if (toolStripMenuItem == this.Goto_Structure_MenuFlottant)
            {
                TreeNode treeNode = (TreeNode)this.Goto_Structure_MenuFlottant.Tag;
                string text = treeNode.Text;
                TreeNode treeNode2 = null;
                while (!(treeNode is ModuleSymbols))
                {
                    treeNode = treeNode.Parent;
                }
                foreach (object obj in treeNode.Nodes)
                {
                    TreeNode treeNode3 = (TreeNode)obj;
                    foreach (object obj2 in treeNode3.Nodes)
                    {
                        TreeNode treeNode4 = (TreeNode)obj2;
                        if (treeNode4.Text == text)
                        {
                            treeNode2 = treeNode4;
                            break;
                        }
                    }
                }
                if (treeNode2 != null)
                {
                    base.SelectedNode = treeNode2;
                    return;
                }
                MessageBox.Show("Structure " + ((ModuleSymbols)this.Remove_Module_MenuFlottant.Tag).Text + " was not found ?!?!", "Problem.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            else
            {
                if (toolStripMenuItem == this.Translate_Module_MenuFlottant)
                {
                    Interaction.SetTextFileTranslate(((ModuleSymbols)this.Remove_Module_MenuFlottant.Tag).ModuleImageHelp.ImageName);
                    Interaction.DisplayTranslatorPanel();
                    return;
                }
                if (toolStripMenuItem == this.ExpandAll_MenuFlottant)
                {
                    base.SuspendLayout();
                    ((TreeNode)this.ExpandAll_MenuFlottant.Tag).ExpandAll();
                    base.ResumeLayout(false);
                    return;
                }
                if (toolStripMenuItem == this.CollapseAll_MenuFlottant)
                {
                    base.SuspendLayout();
                    ((TreeNode)this.CollapseAll_MenuFlottant.Tag).Collapse();
                    base.ResumeLayout(false);
                }
            }
        }

        // Token: 0x060001D3 RID: 467 RVA: 0x000101F0 File Offset: 0x0000F1F0
        private void MenuFlottant_Opening(object sender, CancelEventArgs e)
        {
            this.Create_MenuFlottant();
        }

        // Token: 0x040001F8 RID: 504
        private ContextMenuStrip MenuFlottant;

        // Token: 0x040001F9 RID: 505
        private IContainer components;

        // Token: 0x040001FA RID: 506
        private ToolStripMenuItem Remove_Module_MenuFlottant;

        // Token: 0x040001FB RID: 507
        private ToolStripMenuItem Translate_Module_MenuFlottant;

        // Token: 0x040001FC RID: 508
        private ToolStripMenuItem Goto_Structure_MenuFlottant;

        // Token: 0x040001FD RID: 509
        private ToolStripMenuItem ExpandAll_MenuFlottant;

        // Token: 0x040001FE RID: 510
        private ToolStripMenuItem CollapseAll_MenuFlottant;

        // Token: 0x040001FF RID: 511
        private TreeNode root;

        // Token: 0x04000200 RID: 512
        public ArbreModules.Navigate TreeNavigate;

        // Token: 0x02000048 RID: 72
        public class Navigate
        {
            // Token: 0x060001D4 RID: 468 RVA: 0x000101F8 File Offset: 0x0000F1F8
            private void Init()
            {
                this.TreeNavigate = new List<TreeNode>();
                this.index_courant_nav = -1;
            }

            // Token: 0x060001D5 RID: 469 RVA: 0x0001020C File Offset: 0x0000F20C
            public Navigate(TreeView _tree_view)
            {
                this.tree_view = _tree_view;
                this.Init();
            }

            // Token: 0x060001D6 RID: 470 RVA: 0x00010224 File Offset: 0x0000F224
            public void RefreshNavButton()
            {
                if (this.TreeNavigate.Count < 2)
                {
                    Program.Fenetre.EnableNavigationButtons(false, false);
                    return;
                }
                if (this.index_courant_nav == 0)
                {
                    Program.Fenetre.EnableNavigationButtons(false, true);
                    return;
                }
                if (this.index_courant_nav >= this.TreeNavigate.Count - 1)
                {
                    Program.Fenetre.EnableNavigationButtons(true, false);
                    return;
                }
                Program.Fenetre.EnableNavigationButtons(true, true);
            }

            // Token: 0x060001D7 RID: 471 RVA: 0x00010290 File Offset: 0x0000F290
            public void AddSelectedNode(TreeNode selected_node)
            {
                if (this.index_courant_nav == -1 || selected_node != this.TreeNavigate[this.index_courant_nav])
                {
                    if (this.index_courant_nav < 0)
                    {
                        this.index_courant_nav = 0;
                    }
                    else
                    {
                        this.index_courant_nav++;
                    }
                    if (this.index_courant_nav < this.TreeNavigate.Count)
                    {
                        this.TreeNavigate[this.index_courant_nav] = selected_node;
                        int num = this.TreeNavigate.Count - (this.index_courant_nav + 1);
                        if (num > 0)
                        {
                            this.TreeNavigate.RemoveRange(this.index_courant_nav + 1, num);
                        }
                    }
                    else
                    {
                        this.TreeNavigate.Add(selected_node);
                        if (this.TreeNavigate.Count > 100)
                        {
                            this.TreeNavigate.RemoveAt(0);
                        }
                        this.index_courant_nav = this.TreeNavigate.Count - 1;
                    }
                }
                this.RefreshNavButton();
            }

            // Token: 0x060001D8 RID: 472 RVA: 0x00010374 File Offset: 0x0000F374
            public void SelectedBefore()
            {
                if (this.TreeNavigate.Count > 0)
                {
                    this.index_courant_nav--;
                    if (this.index_courant_nav < 0)
                    {
                        this.index_courant_nav = 0;
                    }
                    this.tree_view.SelectedNode = this.TreeNavigate[this.index_courant_nav];
                }
                this.RefreshNavButton();
            }

            // Token: 0x060001D9 RID: 473 RVA: 0x000103D0 File Offset: 0x0000F3D0
            public void SelectedAfter()
            {
                if (this.TreeNavigate.Count > 0)
                {
                    this.index_courant_nav++;
                    if (this.index_courant_nav >= this.TreeNavigate.Count)
                    {
                        this.index_courant_nav = this.TreeNavigate.Count - 1;
                    }
                    this.tree_view.SelectedNode = this.TreeNavigate[this.index_courant_nav];
                }
                this.RefreshNavButton();
            }

            // Token: 0x060001DA RID: 474 RVA: 0x00010444 File Offset: 0x0000F444
            public void RefreshNavigate()
            {
                List<TreeNode> list = new List<TreeNode>();
                TreeNode treeNode = this.TreeNavigate[this.index_courant_nav];
                bool flag = false;
                using (List<TreeNode>.Enumerator enumerator = this.TreeNavigate.GetEnumerator())
                {
                IL_6D:
                    while (enumerator.MoveNext())
                    {
                        TreeNode treeNode2 = enumerator.Current;
                        if (treeNode2 == treeNode)
                        {
                            flag = true;
                            treeNode = null;
                        }
                        TreeNode treeNode3 = treeNode2;
                        while (!(treeNode3.Text == "Modules"))
                        {
                            treeNode3 = treeNode3.Parent;
                            if (treeNode3 == null)
                            {
                                list.Add(treeNode2);
                                goto IL_6D;
                            }
                        }
                        if (flag && treeNode == null)
                        {
                            treeNode = treeNode2;
                        }
                    }
                }
                foreach (TreeNode item in list)
                {
                    this.TreeNavigate.Remove(item);
                }
                this.index_courant_nav = this.TreeNavigate.IndexOf(treeNode);
                if (this.index_courant_nav == -1)
                {
                    this.Init();
                    return;
                }
                this.tree_view.SelectedNode = this.TreeNavigate[this.index_courant_nav];
            }

            // Token: 0x04000201 RID: 513
            private TreeView tree_view;

            // Token: 0x04000202 RID: 514
            private List<TreeNode> TreeNavigate;

            // Token: 0x04000203 RID: 515
            private int index_courant_nav;
        }

        // Token: 0x02000049 RID: 73
        // (Invoke) Token: 0x060001DC RID: 476
        private delegate void f_node(TreeNode node);

        // Token: 0x0200004A RID: 74
        // (Invoke) Token: 0x060001E0 RID: 480
        private delegate bool f_bool_treenode_array_obj(TreeNode node_base, object obj_user);
    }
}